package com.tledu.mvc03.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * 测试地址参数与SessionAttributes
 * @author Antg
 * @date 2021/8/12  13:59
 */
@RestController
@RequestMapping("/user")
@SessionAttributes(value = {"username"},types = {Integer.class})
public class UserController {
    //地址参数
    @GetMapping("/m1/{username}/{id}")
    public String m1(@PathVariable String username,@PathVariable Integer id){
        return username+" "+id;
    }
    //测试sessionAttributes 存储
    @GetMapping("/m2")
    public String m2(Model model){
        model.addAttribute("username","张三");
        model.addAttribute("id",10);
        return "success";
    }
    //测试sessionAttributes 存储
    @GetMapping("/m3")
    public String m3(Model map){
        System.out.println(map.getAttribute("username"));
        System.out.println(map.getAttribute("id"));
        return "success";
    }
    //清空
    @GetMapping("/m4")
    public String m4(SessionStatus status){
        status.setComplete();
        return "success";
    }
}
